import 'dart:async';
import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';

class PluginNative {
  static VoidCallback _addSuc = () {};

  static MethodChannel _channel = MethodChannel('plugin_native')
    ..setMethodCallHandler(
      (call) {
        ///原生主动向flutter发消息
        return Future(
          () {
            switch (call.method) {
              case "addPlotSuc":
                _addSuc();
                break;
            }
          },
        );
      },
    );

  static Future<String?> get platformVersion async {
    final String? version = await _channel.invokeMethod('getPlatformVersion');
    return version;
  }

  ///当农场创建成功后的回调
  static void onAddPlotSuc(VoidCallback addSuc) {
    _addSuc = addSuc;
  }

  ///跳转新建农场页面
  static Future<void> goToCreateFarm() async {
    if (Platform.isAndroid) {
      await _channel.invokeMethod('goToCreateFarm');
    }
  }
}
